#include <iostream>
#include <future>
#include <chrono>
#include <thread>
void add(int a, int b,std::promise<int> &promise)
{
    std::cout<<"+"<<std::endl;
    promise.set_value(a+b);
}
int main()
{
    std::promise<int> pro;
    std::future<int> fu = pro.get_future();//通过promise获取一个future对象，建立关系
    std::thread thr(add,10,20,std::ref(pro));
    std::cout<<"--------1---------"<<std::endl;
    int sum = fu.get();//从promise中获取异步结果
    std::cout<<sum<<std::endl;
    thr.join();
    return 0;
}